package com.edu.edu.day9_19_week7_homework.SQLite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 9/21 0021.
 */
public class DBHelpter extends SQLiteOpenHelper{

    private static final String DB_NAME="food.db";
    private static final int DB_VERSION = 6;

    //建库
    public DBHelpter(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    //建表
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE food(_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,name CHAR(200))";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //增加列url
        if(newVersion>oldVersion){
            String sql="ALTER TABLE food ADD COLUMN url CHAR(100)";
            db.execSQL(sql);
        }
    }
}
